home *** CD-ROM | disk | FTP | other *** search
/ Champak 52 / Volume 52 - JOGO DISK .iso / Games / shopdrop.swf / scripts / __Packages / PackageHandler.as < prev    next >
Encoding:
Text File  |  2007-09-27  |  5.6 KB  |  200 lines

  1. class PackageHandler
  2. {
  3.    var location;
  4.    var oHandler;
  5.    var vanishing;
  6.    var startY;
  7.    var range;
  8.    var startX;
  9.    var update;
  10.    var nBonusTime;
  11.    var nBalanceTime;
  12.    static var ySpeed = 100;
  13.    var nPack = 5;
  14.    var cPack = 0;
  15.    var bGiftCard = false;
  16.    var baseTime = 5;
  17.    var nBonusRange = 10;
  18.    var cBonusTime = 0;
  19.    var baseBalanceTime = 15;
  20.    var nBalanceRange = 20;
  21.    var cBalanceTime = 0;
  22.    function PackageHandler(loc, mcVanishing)
  23.    {
  24.       this.location = loc;
  25.       this.oHandler = new smashing.ClipHandler(loc,2);
  26.       this.vanishing = mcVanishing;
  27.       var _loc3_ = loc._parent.mcPackageLeft;
  28.       var _loc5_ = loc._parent.mcPackageRight;
  29.       this.startY = _loc3_._y;
  30.       this.range = _loc5_._x - _loc3_._x;
  31.       this.startX = _loc3_._x;
  32.       if(_global.bBonusCard == true || _global.bBalance == true)
  33.       {
  34.          this.update = this.updateCards;
  35.          this.makeBonusTime();
  36.          this.makeBalanceTime();
  37.       }
  38.       else
  39.       {
  40.          this.update = this.updateNormal;
  41.       }
  42.    }
  43.    function updateNormal(nElapsed)
  44.    {
  45.       this.cPack += nElapsed;
  46.       if(this.cPack >= this.nPack)
  47.       {
  48.          this.cPack %= this.nPack;
  49.          this.addPackage();
  50.       }
  51.       var _loc4_ = this.oHandler.clips;
  52.       var _loc5_ = _loc4_.length;
  53.       var _loc3_ = undefined;
  54.       var _loc2_ = 0;
  55.       while(_loc2_ < _loc5_)
  56.       {
  57.          _loc3_ = _loc4_[_loc2_];
  58.          if(_loc3_ != null)
  59.          {
  60.             _loc3_.update(nElapsed);
  61.          }
  62.          _loc2_ = _loc2_ + 1;
  63.       }
  64.    }
  65.    function updateCards(nElapsed)
  66.    {
  67.       this.cPack += nElapsed;
  68.       if(this.cPack >= this.nPack)
  69.       {
  70.          this.cPack %= this.nPack;
  71.          this.addPackage();
  72.       }
  73.       this.cBonusTime += nElapsed;
  74.       if(this.cBonusTime >= this.nBonusTime)
  75.       {
  76.          this.cBonusTime = 0;
  77.          this.makeBonusTime();
  78.          this.addBonusCard();
  79.       }
  80.       this.cBalanceTime += nElapsed;
  81.       if(this.cBalanceTime >= this.nBalanceTime)
  82.       {
  83.          this.cBalanceTime = 0;
  84.          this.makeBalanceTime();
  85.          this.addBalanceIcon();
  86.       }
  87.       var _loc4_ = this.oHandler.clips;
  88.       var _loc6_ = _loc4_.length;
  89.       var _loc3_ = undefined;
  90.       var _loc2_ = 0;
  91.       while(_loc2_ < _loc6_)
  92.       {
  93.          _loc3_ = _loc4_[_loc2_];
  94.          if(_loc3_ != null)
  95.          {
  96.             _loc3_.update(nElapsed);
  97.          }
  98.          _loc2_ = _loc2_ + 1;
  99.       }
  100.    }
  101.    function addPackage()
  102.    {
  103.       var _loc2_ = this.oHandler.addClip("mcPickup");
  104.       _loc2_._y = this.startY;
  105.       _loc2_._x = this.startX + Math.floor(Math.random() * this.range);
  106.       _loc2_.direction = new smashing.Point(this.vanishing._x - _loc2_._x,this.vanishing._y - _loc2_._y);
  107.       _loc2_.origin = new smashing.Point(_loc2_._x,_loc2_._y);
  108.       _loc2_.distance2 = _loc2_.direction.dot(_loc2_.direction);
  109.       _loc2_.direction.normalizeMe();
  110.       _loc2_.lastY = _loc2_._y;
  111.       _loc2_.vanishing = this.vanishing;
  112.       if(this.bGiftCard == true)
  113.       {
  114.          _loc2_.toGiftCard();
  115.       }
  116.       else
  117.       {
  118.          _loc2_.a.pickup.gotoAndStop(Math.ceil(Math.random() * 5));
  119.       }
  120.    }
  121.    function addBonusCard()
  122.    {
  123.       var _loc2_ = this.oHandler.addClip("mcPickup");
  124.       _loc2_._y = this.startY;
  125.       _loc2_._x = this.startX + Math.floor(Math.random() * this.range);
  126.       _loc2_.direction = new smashing.Point(this.vanishing._x - _loc2_._x,this.vanishing._y - _loc2_._y);
  127.       _loc2_.origin = new smashing.Point(_loc2_._x,_loc2_._y);
  128.       _loc2_.distance2 = _loc2_.direction.dot(_loc2_.direction);
  129.       _loc2_.direction.normalizeMe();
  130.       _loc2_.lastY = _loc2_._y;
  131.       _loc2_.vanishing = this.vanishing;
  132.       _loc2_.toBonusCard();
  133.    }
  134.    function addBalanceIcon()
  135.    {
  136.       var _loc2_ = this.oHandler.addClip("mcPickup");
  137.       _loc2_._y = this.startY;
  138.       _loc2_._x = this.startX + Math.floor(Math.random() * this.range);
  139.       _loc2_.direction = new smashing.Point(this.vanishing._x - _loc2_._x,this.vanishing._y - _loc2_._y);
  140.       _loc2_.origin = new smashing.Point(_loc2_._x,_loc2_._y);
  141.       _loc2_.distance2 = _loc2_.direction.dot(_loc2_.direction);
  142.       _loc2_.direction.normalizeMe();
  143.       _loc2_.lastY = _loc2_._y;
  144.       _loc2_.vanishing = this.vanishing;
  145.       _loc2_.toBalanceIcon();
  146.    }
  147.    function reset()
  148.    {
  149.       this.cPack = 0;
  150.       this.oHandler.removeAllClips();
  151.       this.toPackages();
  152.    }
  153.    function toGiftCards()
  154.    {
  155.       this.bGiftCard = true;
  156.       var _loc4_ = this.oHandler.clips;
  157.       var _loc3_ = undefined;
  158.       var _loc2_ = 0;
  159.       while(_loc2_ < _loc4_.length)
  160.       {
  161.          _loc3_ = _loc4_[_loc2_];
  162.          if(_loc3_ != null)
  163.          {
  164.             if(_loc3_.nType == GrabPackage.NORMAL)
  165.             {
  166.                _loc3_.toGiftCard();
  167.             }
  168.          }
  169.          _loc2_ = _loc2_ + 1;
  170.       }
  171.    }
  172.    function toPackages()
  173.    {
  174.       this.bGiftCard = false;
  175.       var _loc4_ = this.oHandler.clips;
  176.       var _loc3_ = undefined;
  177.       var _loc2_ = 0;
  178.       while(_loc2_ < _loc4_.length)
  179.       {
  180.          _loc3_ = _loc4_[_loc2_];
  181.          if(_loc3_ != null)
  182.          {
  183.             if(_loc3_.nType == GrabPackage.NORMAL)
  184.             {
  185.                _loc3_.toPackage();
  186.             }
  187.          }
  188.          _loc2_ = _loc2_ + 1;
  189.       }
  190.    }
  191.    function makeBonusTime()
  192.    {
  193.       this.nBonusTime = this.baseTime + Math.floor(Math.random() * this.nBonusRange);
  194.    }
  195.    function makeBalanceTime()
  196.    {
  197.       this.nBalanceTime = this.baseBalanceTime + Math.floor(Math.random() * this.nBalanceRange);
  198.    }
  199. }
  200.